package pers.lan.hash;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/23 3:20 PM
 */
public class LC_290 {

    public boolean wordPattern(String pattern, String str) {
        String[] words = str.split(" ");
        if (words.length != pattern.length()) {
            return false;
        }
        Map<Object, Integer> mem = new HashMap<>(pattern.length());
        for (int i = 0; i < words.length; i++) {
            if (!Objects.equals(mem.put(words[i], i), mem.put(pattern.charAt(i), i))) {
                return false;
            }
        }
        return true;

    }
}
